import { getExamTopic, getExamTopicListById, getSubjectTree, getTopic, postExamList } from '@/util/request'
import { SubjectTreeType, TopicData, ExamTopicListDateType, ExamTopicType } from '@/util/interface'
import { createAsyncThunk } from '@reduxjs/toolkit'

// 获取阅卷列表 action是dispatch传过来的参数 第一个是extraReducers中res.payload的数据类型 第二个any对应传过来的参数 createAsyncThunk<any, any>
export const get_exam_list_async = createAsyncThunk<any, any>('get/exam_list', async (action, state) => {
  return await postExamList(action)
})

// 获取课程的树型结构
export const get_subject_tree_async = createAsyncThunk<SubjectTreeType[]>('get/subject_tree', async (action, state) => {
  return await getSubjectTree()
})

// 根据二级课程的id获取题目
export const get_topic_list_async = createAsyncThunk<TopicData[], string>('get/topic_list', async (action, state) => {
  return await getTopic(action)
})

// 获取阅卷，查看或者答题试卷时候的列表
export const get_exam_topic_list_async = createAsyncThunk<ExamTopicType, string>('get/exam_topic_list', async (action, state) => {
  return await getExamTopicListById(action)
})

// 学生获取试卷题目
export const get_student_exam_topic_list_async = createAsyncThunk<ExamTopicListDateType[], string>('get/student_exam_topic_list', async (action, state) => {
  return await getExamTopic(action)
})
